﻿// JavaScript Document

document.writeln("    <style type=\"text\/css\">");
document.writeln("        div.dialogMark { position: absolute; -moz-opacity: 0.6; opacity:0.6; filter: alpha(opacity=60); background-color: #a9a9a9;visibility:visible; z-index: 998; left: 0px;height:100%;}");
document.writeln("        div.dialoglayer{position: absolute; z-index: 999;border:1px solid #D8D8D8;background:#F7F7F7;clear:both;margin-bottom:10px;top: 100px; left: 200px; width:400px; overflow:hidden;}");
document.writeln("        div.dialogheader{height:22px ; line-height:22px; background:#E4E4E4;border-bottom:1px solid #d8d8d8;}");
document.writeln("        div.dialogtitle{float:left;font-weight: bold;margin-left:5px;display:inline;}");
document.writeln("        div.dialogclose{float:right;cursor:pointer;width:13px;height:22px;background:url(img\/close.gif) no-repeat center;margin-right:5px;}");
document.writeln("        div.dialogcontent{float:left;padding:4px;display:inline;}");
document.writeln("    <\/style>");
var Dialog={
    head_h:22,
    px:0,
    py:0,
    begin:false,
    isopen:false,
    Show:function(W, H, strValue, IsFrame, Title, Scroll,IsMark,dblclickClose){ //宽 高 内容 是否框架页 标题 滚动条(yes/no) ,遮照 (true/false),双击关闭(true/false)
        if(!Dialog.isopen){
	        /*创建可视窗口*/
	        var divWindow = document.createElement("div");
	        divWindow.id = "dialoglayer";
	        divWindow.className = "dialoglayer";
	        divWindow.style.width = W + "px";
	        Utils.EventUtil.addEvent(divWindow,"dblclick", function() { Dialog.Closes() });
            /*创建可拖动嵌套头*/
	        var divWindowHead = document.createElement("div");
	        divWindowHead.id = "dialogheader";
	        divWindowHead.className = "dialogheader";
	        divWindowHead.style.width = W + "px";
	        Utils.EventUtil.addEvent(divWindowHead,"mousedown", function(ev) { Dialog.MouseDown(ev) });
	        Utils.EventUtil.addEvent(divWindowHead,"mousemove", function(ev) { Dialog.MouseMove(ev) });
	        Utils.EventUtil.addEvent(divWindowHead,"mouseup", function(ev) { Dialog.MouseUp(ev) });

	        /*创建可拖动嵌套标题*/
	        var divWindowTitle = document.createElement("div");
	        divWindowTitle.id = "dialogtitle";
	        divWindowTitle.className = "dialogtitle";
	        divWindowTitle.innerHTML=Title;
        	
	        /*创建可拖动嵌套关闭*/
	        var divWindowClose = document.createElement("div");
	        divWindowClose.id = "dialogclose";
	        divWindowClose.className = "dialogclose";
	        divWindowClose.title="关闭";
	        Utils.EventUtil.addEvent(divWindowClose,"click", function() { Dialog.Closes() });
    	    
	        /*创建窗口内容层*/
	        var divWindowContent = document.createElement("div");
	        divWindowContent.id = "dialogcontent";
	        divWindowContent.className = "dialogcontent";
            if(Utils.IsIE)divWindowContent.style.width = W + "px";
            else divWindowContent.style.width = W-4 + "px";
            
	        /*创建可拖动嵌套关闭头*/
	        divWindowHead.appendChild(divWindowTitle);//为窗口头部文件压入标题功能
	        divWindowHead.appendChild(divWindowClose); //压入关闭按钮
    	    
	        divWindow.appendChild(divWindowHead); //压入头部
	        divWindow.appendChild(divWindowContent); //压入内容区
    	    
	        window.document.body.appendChild(divWindow);//压入到网页区
	        /*创建Mark层*/
	        if(IsMark){
	            var divWindowMark = document.createElement("div");
	            divWindowMark.id = "dialogMark";
	            divWindowMark.className = "dialogMark";
                divWindowMark.style.display = "block";
                divWindowMark.style.width = Dialog.getPageSize().width+"px";
	            divWindowMark.style.top="0px";
                divWindowMark.style.height = Dialog.getPageSize().height+"px";
	            window.document.body.appendChild(divWindowMark);
	        }
	        if(IsFrame){ //是否引用页
		        var frmWindow = document.createElement("iframe");
		        frmWindow.id = "frmWindow";
		        frmWindow.setAttribute("name", "frmWindow", 0);
		        frmWindow.setAttribute("frameBorder",0); 
		        frmWindow.className = "frmWindow";
		        //frmWindow.frameBorder = "0px";
		        frmWindow.style.overflow = "hidden";
		        frmWindow.style.width = W-4+"px";
		        frmWindow.style.height = H-Dialog.head_h+"px";
		        divWindowContent.appendChild(frmWindow);
		        frmWindow.scrolling = Scroll;
		        frmWindow.src = strValue;
		        if(dblclickClose)Utils.EventUtil.addEvent(frmWindow,"load", function() {(this.contentWindow || frames["frmWindow"]).document.ondblclick=function(){parent.Dialog.Closes()}});	    
	        }else{
		        divWindowContent.innerHTML=strValue;	
	        }
	        if(H<divWindow.offsetHeight)H=divWindow.offsetHeight; //实际高度
	        /*初始化弹出层窗口位置*/
            var clientHeight = document.documentElement.clientHeight>0?document.documentElement.clientHeight:document.body.clientWidth;  
            var clientWidth = document.documentElement.clientWidth >0?document.documentElement.clientWidth:document.body.clientHeight;
            var left = (clientWidth - W) / 2;
            var top =(clientHeight - H) / 2+document.documentElement.scrollTop;
            if(top < 20) top = 20;
            //if(top > 150) top = 150;
            divWindow.style.width = W + "px";
            divWindow.style.height = H + "px";
            divWindow.style.left = left + "px";
            divWindow.style.top = top + "px";
            //document.documentElement.style.overflow = "hidden";
            divWindow.style.display = "block";
            divWindow.style.visibility = "visible";
            Dialog.isopen=true;
        }else alert("窗口已存在，请先关闭！");
    },
    MouseDown:function(ev){
        var divWindow = document.getElementById("dialoglayer");
	    var divWindowHead = document.getElementById("dialogheader");
	    divWindow.z = 999;
        var event = ev || window.event;
        if(Utils.IsIE) event.srcElement.setCapture();
        else
        {
            document.addEventListener('mousemove',function(event) { Dialog.MouseMove(event) },true);
            document.addEventListener('mouseup',function(event) { Dialog.MouseUp(event) },true);
        }

        Dialog.begin = true;
        if(Utils.IsIE){
            Dialog.px = divWindow.style.pixelLeft - event.x;
            Dialog.py = divWindow.style.pixelTop - event.y;
        }
        else{
            Dialog.px = parseInt(divWindow.style.left) - event.clientX;
            Dialog.py = parseInt(divWindow.style.top) - event.clientY;
        }
    },
    MouseUp:function(ev){
        var divWindow = document.getElementById("dialoglayer");
	    var divWindowHead = document.getElementById("dialogheader");
        if(divWindow){
            var event = ev || window.event;
            
            Dialog.begin = false;
            divWindowHead.style.cursor = "default";
            if(Utils.IsIE) event.srcElement.releaseCapture();
            else
            {
                document.removeEventListener('mousemove',function(event) { Dialog.MouseMove(event) },true);
                document.removeEventListener('mouseup',function(event) { Dialog.MouseUp(event) },true);
            }
        }
    },
    MouseMove:function(ev){
        var divWindow = document.getElementById("dialoglayer");
	    var divWindowHead = document.getElementById("dialogheader");
        if(divWindow){
		    divWindowHead.style.cursor = "move";
            if(Dialog.begin){
                var event = ev || window.event;
                if(Utils.IsIE){
                    divWindow.style.pixelLeft = (Dialog.px + event.x);
                    divWindow.style.pixelTop = (Dialog.py + event.y);
                }
                else{
                    divWindow.style.left = (Dialog.px + event.clientX)+"px";
                    divWindow.style.top = (Dialog.py + event.clientY)+"px";
                }
            }
        }
    },
    Closes:function (){
       var frmWindow=document.getElementById("frmWindow");
	    if(frmWindow){
		    frmWindow.src="about:blank";
	    }
        var divWindow = document.getElementById("dialoglayer");
	    document.body.removeChild(divWindow);
	    var divWindowMark=document.getElementById("dialogMark");
	    if(divWindowMark){
            divWindowMark.style.display = "none";
	        document.body.removeChild(divWindowMark);
	    }
	    Dialog.isopen=false;
    },
    getPageSize:function(){ //内容区实际高度
        var re = {};
        if (document.documentElement && document.documentElement.clientHeight)
        {
            var doc = document.documentElement;
            re.width = (doc.clientWidth>doc.scrollWidth)?doc.clientWidth-1:doc.scrollWidth;
            re.height = (doc.clientHeight>doc.scrollHeight)?doc.clientHeight:doc.scrollHeight;
        }
        else
        {
            var doc = document.body;
            re.width = (window.innerWidth>doc.scrollWidth)?window.innerWidth:doc.scrollWidth;
            re.height = (window.innerHeight>doc.scrollHeight)?window.innerHeight:doc.scrollHeight;
        }
        return re;
    }

}
